<template>
<div>
  <van-nav-bar title="绑定住院人" left-text="返回"
               left-arrow  @click-left="back"/>
  <div>
    <van-form >
      <van-cell-group inset>
        <van-field
            v-model="obj.hzid"
            label="住院区"
            placeholder="请输入住院区"
            :rules="[{ required: true, message: '请填写住院区' }]"
        />
        <van-field
            v-model="obj.sid"
            label="住院科室"
            placeholder="请输入住院科室"
            :rules="[{ required: true, message: '请填写住院科室' }]"
        />
        <van-field
            v-model="obj.no"
            label="住院号"
            placeholder="请输入住院号"
            :rules="[{ required: true, message: '请填写住院号' }]"
        />
        <van-field name="radio" label="住院状态">
          <template #input>
            <van-radio-group v-model="obj.flag" direction="horizontal">
              <van-radio name="1">住院中</van-radio>
              <van-radio name="2">已出院</van-radio>
            </van-radio-group>
          </template>
        </van-field>
        <van-field
            v-model="obj.stime"
            is-link
            readonly
            label="入院时间"
            placeholder="点击选择入院时间"
            @click="showCalendar1 = true"
        />
        <van-calendar v-model:show="showCalendar1" @confirm="selectstime" />
        <van-field
            v-model="obj.etime"
            is-link
            readonly
            label="出院时间"
            placeholder="点击选择出院时间"
            @click="showCalendar2 = true"
        />
        <van-calendar v-model:show="showCalendar2" @confirm="selectetime" />
      </van-cell-group>

      <van-cell-group style="margin-top: 20px" inset>
        <van-field
            v-model="patient.name"
            label="就诊人"
            readonly
        />
        <van-field
            v-model="patient.cardType"
            label="证件类型"
            readonly
        />
        <van-field
            v-model="patient.cardNo"
            label="证件号"
            readonly
        />
        <van-field
            v-model="patient.phone"
            label="手机号"
            readonly
        />
        <van-field
            v-model="patient.no"
            label="就诊卡号"
            readonly
        />
      </van-cell-group>

      <div style="margin: 16px;">
        <van-button round block type="primary" native-type="button" @click="add">
          确定
        </van-button>
      </div>
    </van-form>


  </div>
</div>
</template>

<script setup>
import {ref,onMounted} from "vue";
import axios from "axios";
import {useRouter} from "vue-router";
import {useStore} from "vuex";
const store = useStore()
const router = useRouter()
const patient=store.state.bindpatient;
const obj=new ref({})

const showCalendar1=ref(false);
const showCalendar2=ref(false);

const selectstime = (date) => {
  obj.value.stime= `${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()}`+" 09:00:00";
  showCalendar1.value=false;
}
const selectetime = (date) => {
  obj.value.etime= `${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()}`+" 18:00:00";
  showCalendar2.value=false;
}
const back=()=>{
  history.back();
}
const add = () => {
  //新增 请求接口 axios
  obj.value.uid=store.state.user.id;
  obj.value.pid=patient.id;
  axios.post("hospitalized/add",obj.value).then(res=>{
    if(res.data.code==0){
      //跳转
      router.push("/hospitalizedlist")
    }
  })
}
</script>

<style scoped>

</style>
